import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/models/report/bookReleaseChartData.dart';
import 'package:ichinesereader/themes/hexColor.dart';
import 'package:ichinesereader/utils/helper.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import '../../themes/appTheme.dart';

class BookReleaseWidget extends StatelessWidget {
  BookReleaseWidget({Key? key, required this.bookReleaseData})
      : super(key: key);
  final List<BookReleaseChartData> bookReleaseData;

  @override
  Widget build(BuildContext context) {
    Log.debug('build BookReleaseWidget');
    TooltipBehavior _tooltipBehavior = TooltipBehavior(
        enable: true,
        color: Get.isDarkMode
            ? AppTheme.colors.darkTheme1
            : Colors.white.withOpacity(0.1),
        duration: 2000,
        // tooltipPosition: TooltipPosition.pointer,
        // opacity: 1,
        builder: (dynamic data, dynamic point, dynamic series, int pointIndex,
            int seriesIndex) {
          return Container(
            decoration: BoxDecoration(
              border: Border.all(
                color: HexColor(data.book.level?.color),
                width: 9,
              ),
              color: Get.isDarkMode ? AppTheme.colors.darkTheme3 : Colors.white,
              borderRadius: BorderRadius.circular(6),
            ),
            width: 450,
            height: 203,
            child: Column(
                //padding: const EdgeInsets.all(12),
                children: [
                  Flexible(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Flexible(
                            flex: 1,
                            child: Column(
                              children: [
                                Image.network(data.book.imageLink),
                              ],
                            )),
                        Flexible(
                            flex: 2,
                            child: Padding(
                              padding: const EdgeInsets.only(left: 12.0),
                              child: Column(
                                children: [
                                  Column(
                                    children: [
                                      Text(
                                          data.book.bookTitle != null
                                              ? data.book.bookTitle
                                              : '',
                                          style: TextStyle(
                                              fontSize: 15.0,
                                              fontWeight: FontWeight.bold,
                                              color: Get.isDarkMode
                                                  ? Get.theme.primaryColorDark
                                                  : Colors.blueGrey)),
                                      Text(
                                        data.book.englishTitle != null
                                            ? data.book.englishTitle
                                            : '',
                                      ),
                                    ],
                                  ),
                                  Text(
                                      data.book.level.displayName != null
                                          ? data.book.level.displayName
                                          : "Unleveled",
                                      style: TextStyle(
                                          fontSize: 12.0,
                                          fontStyle: FontStyle.italic,
                                          color: Get.isDarkMode
                                              ? Get.theme.primaryColorDark
                                              : Colors.grey)),
                                  Text(
                                    data.book.textType != null
                                        ? data.book.textType
                                        : '',
                                    style: TextStyle(
                                        color: Get.isDarkMode
                                            ? Get.theme.primaryColorDark
                                            : Colors.black),
                                  ),
                                  // Text(
                                  //   data.book.bookFeatures != null
                                  //       ? data.book.bookFeatures
                                  //       : '',
                                  //   style: TextStyle(
                                  //       color: Get.isDarkMode
                                  //           ? Get.theme.primaryColorDark
                                  //           : Colors.black),
                                  // ),
                                  Text(
                                    data.book.description != null
                                        ? data.book.description
                                        : '',
                                    maxLines: 4,
                                    style: TextStyle(
                                        overflow: TextOverflow.ellipsis,
                                        color: Get.isDarkMode
                                            ? Get.theme.primaryColorDark
                                            : Colors.black),
                                  ),
                                ],
                              ),
                            ))
                      ],
                    ),
                  )
                ]),
          );
        });
    return SfCartesianChart(
        primaryXAxis: CategoryAxis(),
        tooltipBehavior: _tooltipBehavior,
        title: ChartTitle(
          text: 'New Releases'.tr,
          alignment: ChartAlignment.near,
          textStyle: TextStyle(
            color: Get.isDarkMode
                ? Get.theme.primaryColorDark
                : Get.theme.primaryColorLight,
            fontFamily: 'Montserrat',
            fontSize: 18.0,
          ),
        ),
        series: <ChartSeries>[
          ScatterSeries<BookReleaseChartData, String>(
              dataSource: bookReleaseData,
              enableTooltip: true,
              pointColorMapper: (BookReleaseChartData data, _) =>
                  HexColor(data.book.level?.color),
              xValueMapper: (BookReleaseChartData data, _) =>
                  parseDate(int.parse(data.date)),
              yValueMapper: (BookReleaseChartData data, _) => data.value,
              markerSettings: MarkerSettings(
                  height: 9.0, width: 42, shape: DataMarkerType.rectangle))
        ]);
  }
}
